<template>
  <div>
    <el-form label-width="80px" :inline="true" size="small">
      <el-form-item label="一级分类">
        <el-select
          v-model="c1Id"
          placeholder="请选择一级分类"
          @change="changeC1Id"
          :disabled='scene==0?false:true'
        >
          <el-option
            v-for="c1 in c1Arr"
            :key="c1.Id"
            :label="c1.name"
            :value="c1.id"
            
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="二级分类">
        <el-select
          v-model="c2Id"
          placeholder="请选择二级分类"
          @change="changeC2Id"
          :disabled='scene==0?false:true'
        >
          <el-option
            v-for="c2 in c2Arr"
            :key="c2.Id"
            :label="c2.name"
            :value="c2.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="三级分类">
        <el-select
          v-model="c3Id"
          placeholder="请选择三级分类"
          @change="changeC3Id"
          :disabled='scene==0?false:true'
        >
          <el-option
            v-for="c3 in c3Arr"
            :key="c3.Id"
            :label="c3.name"
            :value="c3.id"
          ></el-option>
        </el-select>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: "Category",
  data() {
    return {
      c1Id: "",
      c1Arr: [],
      c2Id: "",
      c2Arr: [],
      c3Id: "",
      c3Arr: [],
    };
  },
  props:['scene'], 
  mounted() {
    this.getC1List();
  },
  methods: {
    async getC1List() {
      let res = await this.$API.category.getCategory1();
      this.c1Arr = res.data;
      
    },
    async changeC1Id() {
      this.c2Id = "";
      this.c2Arr = [];
      this.c3Id = "";
      this.c3Arr = [];
      let res = await this.$API.category.getCategory2(this.c1Id);
      this.c2Arr = res.data;
      this.$emit("c3IdChangeHandle",{c1Id:this.c1Id});
    },
    async changeC2Id() {
      this.c3Id = "";
      this.c3Arr = [];
      let res = await this.$API.category.getCategory3(this.c2Id);
      this.c3Arr = res.data;
      this.$emit("c3IdChangeHandle",{c1Id:this.c1Id,c2Id:this.c2Id});
    },
    changeC3Id() {
      const {c1Id,c2Id,c3Id}=this;
      this.$emit("c3IdChangeHandle", {c1Id,c2Id,c3Id});
    },
  },
};
</script>

<style lang="scss" scoped>
</style>